package com.cloud.quickcore.admin.controller;

import com.cloud.quickcommon.R;
import com.cloud.quickcore.admin.dto.SysRoleDto;
import com.cloud.quickcore.admin.entity.SysRole;
import com.cloud.quickcore.admin.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色表--Controller
 * @author NiJo_H
 * @version 1.0
 * @date 2019/8/11 14:32
 */
@Api(tags = "后台-角色管理")
@RestController
@RequestMapping(value = "/admin/role")
@Slf4j
public class SysRoleController {
    @Autowired
    private SysRoleService roleService;

    @ApiOperation(value = "添加角色")
    @PostMapping
    public R<Void> addRole(@RequestBody SysRoleDto dto){
        log.info("添加角色操作,接收参数:{}",dto);
        roleService.save(dto);
        return R.ok();
    }

    @ApiOperation(value = "角色列表")
    @GetMapping
    @RequiresPermissions("system:user")
    public R<List<SysRole>> findAllRole(){
        log.info("查询角色操作");
        return R.ok(roleService.findAll());
    }

    @ApiOperation(value = "删除角色")
    @DeleteMapping
    public R<Void> deleteRole(Long roleId){
        log.info("请求删除角色,传入参数{}",roleId);
        roleService.romve(roleId);
        return R.ok();
    }

    @ApiOperation("更新角色")
    @PutMapping
    public R<Void> updateRole(@RequestBody SysRoleDto dto){
        log.info("请求更新角色,传入参数{}",dto);
        roleService.update(dto);
        return R.ok();
    }



}
